<template>
    <view class="page-bottom-fixed" v-if="status == 1">
		<view v-if="(data_base || null) == null || data_base.is_enable_cash == 0">
			<view class="new_ts_box">积分提现暂时关闭！</view>
		</view>
		<view v-else>
			<view class="form-container padding-main">
				<view class="score_box bg-main spacing-mb border-radius-main padding-lg">
					<view class="title">积分余额</view>
					<view class="ftitle">{{user_score.integral}}</view>
					<view class="ftitle2 dis-none">(含赠送的{{user_score.zeng_integral}}积分)</view>
					<view class="score_box_ff">
						<view class="ff-item">提现最低积分：<text v-if="data_base.cash_minimum_amount == ''">不限制</text><text v-else>{{data_base.cash_minimum_amount}}</text></view>
						<view class="ff-item">提现手续费：<text>{{data_base.integral_cut_bili}}%</text></view>
					</view>
				</view>
				<view class="form-gorup padding-vertical-main">
					<input type="digit" name="money" :value="recharge_money_value || ''" placeholder-class="cr-grey" class="cr-base text-size-xxl" placeholder="请输入要提现积分" @input="recharge_money_value_input_event" maxlength="6">
				</view>

				<view class="form-gorup form-gorup-submit">
					<button class="round cr-white bg-main br-main text-size" type="default" hover-class="none" :disabled="form_submit_disabled_status" @tap="form_submit_event">提交</button>
				</view>
				
				<view v-if="(data_base || null) != null && data_base.tixian_notice != ''" class="page_ts_box">
					<view><text>提现说明：</text>{{data_base.tixian_notice}}</view>
				</view>
			</view>
		</view>
    </view>
</template>
<script>
    const app = getApp();
    import componentNoData from "@/components/no-data/no-data";

    export default {
        data() {
            return {
                params: null,
                form_submit_loading: false,
                data_list_loding_status: 1,
                data_list_loding_msg: '',
                data_base: null,
                user_score: null,
				recharge_money_value: '',
				form_submit_disabled_status: false,
                can_cash_max_money: 0.00,
				status:0,
            };
        },

        components: {
            componentNoData
        },
        props: {},

        onLoad(params) {
            this.setData({
                params: params
            });
        },

        onShow() {
			app.globalData.page_event_onshow_handle();
            this.init();

            // 分享菜单处理
            app.globalData.page_share_handle();
        },

        // 下拉刷新
        onPullDownRefresh() {
            this.get_data();
        },

        methods: {
            init() {
                var user = app.globalData.get_user_info(this, "init");
                if (user != false) {
                    this.get_data();
                } else {
                    this.setData({
                        data_list_loding_status: 2,
                        data_list_loding_msg: '请先授权用户信息'
                    });
                }
            },

            // 获取数据
            get_data() {
                this.setData({
                    data_list_loding_status: 1
                });
                uni.showLoading({
                    title: this.$t('common.loading_in_text'),
                });
                uni.request({
                    url: app.globalData.get_request_url("createinit", "cash", "scorestore"),
                    method: 'POST',
                    data: {},
                    dataType: 'json',
                    success: res => {
                        uni.hideLoading();
                        uni.stopPullDownRefresh();
                        if (res.data.code == 0) {
                            var data = res.data.data || null;
                            this.setData({
                                data_list_loding_status: 3,
                                data_base: data.base || null,
                                user_score: data.user_score || null,
                                can_cash_max_money: parseFloat(data.can_cash_max_money) || 0.00,
								status:1,
                            });
                        } else {
                            this.setData({
                                data_list_loding_status: 2,
                                data_list_loding_msg: res.data.msg
                            });
                            if (app.globalData.is_login_check(res.data)) {
                                app.globalData.showToast(res.data.msg);
                            }
                        }
                    },
                    fail: () => {
                        uni.hideLoading();
                        uni.stopPullDownRefresh();
                        this.setData({
                            data_list_loding_status: 2,
                            data_list_loding_msg: this.$t('common.internet_error_tips')
                        });
                        app.globalData.showToast(this.$t('common.internet_error_tips'));
                    }
                });
            },
			
			// 充值金额输入事件
			recharge_money_value_input_event(e) {
			    this.setData({
			        recharge_money_value: e.detail.value || ''
			    });
			},

            // 数据提交
            form_submit_event() {
                // 参数
                if ((this.recharge_money_value || null) == null) {
                    app.globalData.showToast('请输入提现积分数');
                    return false;
                }
				var self = this;
				uni.showModal({
				    title: '温馨提示',
				    content: '确定即意味着您已阅读并理解了《提现说明》，确定继续吗？',
				    confirmText: '确定',
				    cancelText: '取消',
				    success: function (res) {
						if (res.confirm) {
							self.real_submit_event();
						}
				    }
				});
            },
			real_submit_event(e) {
                this.setData({
                    form_submit_disabled_status: true
                });
                uni.showLoading({
                    title: '处理中...'
                });
                uni.request({
                    url: app.globalData.get_request_url("create", "cash", "scorestore"),
                    method: 'POST',
                    data: {
                        money: this.recharge_money_value
                    },
                    dataType: 'json',
                    success: res => {
                        this.setData({
                            form_submit_disabled_status: false
                        });
                        uni.hideLoading();
						
                        if (res.data.code == 0) {
							app.globalData.showToast(res.data.msg, 'success');
							
							setTimeout(function() {
							    app.globalData.url_open('/pages/plugins/wallet/user/user', true);
							}, 1500);
                        } else {
                            if (app.globalData.is_login_check(res.data)) {
                                app.globalData.showToast(res.data.msg);
                            } else {
                                app.globalData.showToast('提交失败，请重试！');
                            }
                        }
                    },
                    fail: () => {
                        this.setData({
                            form_submit_disabled_status: false
                        });
                        uni.hideLoading();
                        app.globalData.showToast(this.$t('common.internet_error_tips'));
                    }
                });
            }
        }
    };
</script>
<style>
    @import './cash-create';
</style>